using GameProtocol;
using System;
using System.Collections;
using System.Collections.Generic;
using TEngine;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace GameLogic
{
    public class SlotInBluemapUI : MonoBehaviour, IPointerClickHandler
    {
        Action<int> m_OnSelectedCallback;
        int m_ID = -1;

        public Action<int> OnSelectedCallback { get => m_OnSelectedCallback; set => m_OnSelectedCallback = value; }

        public void OnPointerClick(PointerEventData eventData)
        {
            if (m_OnSelectedCallback != null)
                m_OnSelectedCallback.Invoke(m_ID);
        }

        public void Init(SlotDesignData designData, int id)
        {
            m_ID = id;
            transform.localPosition = new Vector3(512*(designData.PosX / 1000f), 512 * (designData.PosY / 1000f));
            transform.localScale = Vector3.one;

            var spriteChanger = transform.FindChildComponent<SpriteChanger>("Root/m_sChangerBG");
            int spriteIdx = 0;
            spriteIdx += (designData.SlotType == (int)GameConfig.slot.EType.Assistance ? 3 : 0);
            spriteChanger.ChangeToIndex(spriteIdx);
        }
        public void SwitchWeapon(int weaponID)
        {
            var previewImg = transform.FindChildComponent<Image>("Root/m_imgEquipmentPreview");
            previewImg.gameObject.SetActive(weaponID > 0);
            previewImg.sprite = WeaponModule.Instance.GetWeaponSprite(weaponID);
        }

        void Start()
        {
        
        }

        // Update is called once per frame
        void Update()
        {
        
        }
    }
}
